<template>
	<view class="show-player-info">
		<view class="show-avatar">
			<image :src="avatarImg"></image>
		</view>
		<view class="info-edit">
			<view class="cu-form-group">
				<view class="title">玩家名</view>
				<input disabled v-model="playerName" placeholder="玩家名"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">入学年份</view>
				<input disabled v-model="enrollmentYear" placeholder="入学年份"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">性别</view>
				<input disabled v-model="gender" placeholder="性别"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">QQ号</view>
				<input disabled v-model="qq" placeholder="QQ号"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">电话</view>
				<input disabled v-model="phone" placeholder="电话"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">邮箱</view>
				<input disabled v-model="email" placeholder="邮箱"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">所在学校</view>
				<input disabled v-model="school" placeholder="所在学校"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">所在学院</view>
				<input disabled v-model="college" placeholder="所在学院"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">专业</view>
				<input disabled v-model="major" placeholder="专业"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">宿舍地址</view>
				<input disabled v-model="dormitoryAddr" placeholder="宿舍地址"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">金币</view>
				<input disabled v-model="goldCoin" placeholder="金币"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">节操币</view>
				<input disabled v-model="integrity" placeholder="节操币"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">会员类型</view>
				<input disabled v-model="memberType" placeholder="会员类型"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">称号</view>
				<input disabled v-model="title" placeholder="称号"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">等级</view>
				<input disabled v-model="level" placeholder="等级"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">是否已婚(游戏中)</view>
				<input disabled v-model="isMarried" placeholder="是否已婚"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">最后登录时间</view>
				<input disabled v-model="lastLogin" placeholder="最后登录时间"></input>
			</view>
		</view>
	</view>
</template>

<script>
	import ajax from '../../../Ajax/index.js'
	export default {
		data() {
			return {
				avatarImg: '',
				playerName: '',
				enrollmentYear: '',
				gender: '',
				qq: '',
				phone: '',
				email: '',
				school: '',
				college: '',
				major: '',
				dormitoryAddr: '',
				goldCoin: '',
				integrity: '',
				memberType: '',
				title: '',
				level: '',
				isMarried: '',
				lastLogin: ''
			}
		},
		onLoad(e) {
			console.log(e);
			if(e.playerName != undefined) {
				this.playerName = e.playerName
				this.getPlayerInfo()
				this.getMcrmbPlayerInfo()
				this.getPlayerEconInfo()
				this.getPlayerAvatar()
			} else {
				uni.showToast({title: '玩家名为空', icon: 'none'})
			}
		},
		mounted() {
			
		},
		methods: {
			getPlayerInfo() {
				let param = new URLSearchParams()
				param.append("playerName", this.playerName)
				ajax.post('account/getPlayerInfo', param).then(res => {
					if(res.data.code == 200) {
						let r = res.data.playerInfo
						this.enrollmentYear = new Date(r.enrollmentYear).toLocaleDateString()
						this.gender = r.gender == '1' ? '男' : '女'
						this.qq = r.qq
						this.phone = r.phone
						this.email = r.email
						this.school = r.school
						this.college = r.college
						this.major = r.major
						this.dormitoryAddr = r.dormitoryAddr
						this.memberType = this.getPlayerMemType(r.memberType)
						this.title = r.title || '无'
						this.level = r.level || '无'
						this.isMarried = r.isMarried == 0 ? '未婚' : '已婚'
						this.lastLogin = new Date(r.lastLogin).toLocaleDateString()
					}
				})
			},
			getPlayerMemType(type) {
				switch(type) {
					case 0: return '普通玩家';
					case 1: return 'VIP玩家';
					case 2: return 'SVIP玩家';
					case 3: return '至尊SVIP玩家';
				}
			},
			getMcrmbPlayerInfo() {
				let param = new URLSearchParams()
				param.append("playerName", this.playerName)
				ajax.post('mcrmb/getPlayerMcRmbInfo', param).then(res => {
					if (res.data.code == 101) {
						this.integrity = res.data.data[0].money
					}
				})
			},
			getPlayerEconInfo() {
				let param = new URLSearchParams()
				param.append("playerName", this.playerName)
				ajax.post('economy/getPlayerEconomy', param).then(res => {
					if (res.data.code == 200) {
						this.goldCoin = res.data.res.balance
					}
				})
			},
			getPlayerAvatar() {
				let param = new URLSearchParams()
				param.append("playerName", this.playerName)
				ajax.post('avatar/getAvatar', param).then(res => {
					if (res.data.code == 200) {
						this.avatarImg = res.data.res.avatar
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.show-player-info {
		.show-avatar {
			display: flex;
			justify-content: center;
			align-items: center;
			image {
				width: 500rpx;
				height: 500rpx;
			}
		}
	}
</style>
